/**
 * 零件承认流程（当前零部件只有为“Design”视图对象并且状态在“新品”状态下才能走）
 */
package ext.tianma.validators;
import java.rmi.RemoteException;
import java.util.Locale;

import wt.fc.WTReference;
import wt.org.WTUser;
import wt.part.WTPart;
import wt.session.SessionHelper;
import wt.util.WTException;

import com.ptc.core.ui.validation.DefaultUIComponentValidator;
import com.ptc.core.ui.validation.UIValidationCriteria;
import com.ptc.core.ui.validation.UIValidationKey;
import com.ptc.core.ui.validation.UIValidationResult;
import com.ptc.core.ui.validation.UIValidationResultSet;
import com.ptc.core.ui.validation.UIValidationStatus;

import ext.com.iba.IBAUtil;



public class BlueprintReleaseValidator extends DefaultUIComponentValidator{
	
	private static final String D_VIEW = "Design";
	
	public UIValidationResultSet performFullPreValidation(UIValidationKey uivalidationkey, UIValidationCriteria uivalidationcriteria, Locale locale) throws WTException {
		UIValidationStatus uivalidationstatus = UIValidationStatus.HIDDEN;
		UIValidationResultSet uivresultSet = new UIValidationResultSet();
		boolean flag = false;
		if (uivalidationcriteria != null && uivalidationcriteria.getContextObject() != null) {
			WTReference wtreference = uivalidationcriteria.getContextObject();
			wt.fc.Persistable persistable = wtreference.getObject();
			WTUser curUser = (WTUser) SessionHelper.manager.getPrincipal();
			WTPart part = (WTPart) persistable;
			
			if( part != null ){
				String partView = part.getViewName();
				
				if( partView != null && partView.equals( D_VIEW ) ){
					//是否需要样品承认
					String recognize=null;
					try {
						recognize = (String)IBAUtil.getIBAValue(part,"partRecognize");
						if(recognize.equals("是"))
						{
							String state = part.getLifeCycleState().toString();
							if(state.equals("NewProduct"))
							{
								flag = true;
							}
						}
					} catch (RemoteException e) {
						e.printStackTrace();
					}
				}
			}
		}
		if (flag) {
			uivresultSet.addResult(new UIValidationResult(uivalidationkey, UIValidationStatus.ENABLED));
		} else {
			uivresultSet.addResult(new UIValidationResult(uivalidationkey, UIValidationStatus.HIDDEN));
		}
		return uivresultSet;
	}
}
